/**
 * 表格控件的表头分隔符控件
 * @class 表头分隔符控件类
 */
function splitter() {
  this._width = 500;
  this._height = 300;

  this._leftWidth = 100;

  this._tbPanel = new panel(1, 3);
  this._panelDom = this._tbPanel.render();

  this._status = 0; // 1 - mousedown
  this._OriginPosX = 0;
  this._OriginPosY = 0;
}

zxt.defineClazz(splitter, zxt.ui.Widget);

/**
 * 返回控件类型
 * 
 * @function
 * @return {string} "splitter"
 */
splitter.prototype.getType = function(){
  return "splitter";
}

/**
 * <p>
 * 渲染该组合输入框的DOM节点
 * </p>
 * 
 * @function
 * @return {DOM} 渲染成的DOM节点
 */
splitter.prototype.renderSelf = function(){
  var host = this;

  $(this._panelDom).height(this._height);
  $(this._panelDom).width(this._width);


  var left = this._tbPanel.getCell(0, 0);
  $(left).css("backgroundColor", "#f0f3f4");
  $(left).width(this._leftWidth);

  var right = this._tbPanel.getCell(0, 2);
  $(right).css("backgroundColor", "#f0f3f4");

  var split = this._tbPanel.getCell(0, 1);
  $(split).width("1");
  $(split).css("backgroundColor", "#D2D3D4");
  $(split).css("cursor", "e-resize");
  $(split).html("<IMG src=\"../src/resource/images/vgrabber.gif\" >");
  
  
  $(split).mousedown( function(e){ host.mouseDownOnSplit(e);} );
  $(this._panelDom).mousemove( function(e){host.mouseMove(e);} );
  $(this._panelDom).mouseup( function(e){host.mouseUp(e);} );
  
  return this._panelDom;
}

/**
 * 分隔符鼠标按下事件
 * @function
 * @event
 * @param {Event} e
 */
splitter.prototype.mouseDownOnSplit = function(e){
  if (this._status == 0) {
	  var ev = system.getEvent(e);
	  this._status = 1;				
  	  this._OriginPosX = ev.screenX;		
  	  this._OriginPosY = ev.screenY;
  	}
}

/**
 * 分隔符鼠标移动事件
 * @function
 * @event
 * @param {Event} e
 */
splitter.prototype.mouseMove  = function(e){
  if ( this._status != 1 ) return;
  var ev = system.getEvent(e);
  var pos_x = ev.screenX;
  var pos_y = ev.screenY;
  
  var minus_px = pos_x - this._OriginPosX;
  if (Math.abs(minus_px) < 2) return; 

   this.resize(minus_px);    
   this._OriginPosX = pos_x;		
   this._OriginPosY = pos_y;		
}

/**
 * 分隔符鼠标释放事件
 * @function
 * @event
 * @param {Event} e
 */
splitter.prototype.mouseUp  = function(){
  this._status = 0;
}

/**
 * 分隔符宽度调整事件
 * @function
 * @event
 * @param {int} sz 调整的数值 正数加宽 负数减小
 */
splitter.prototype.resize = function(sz){
  var left = this._tbPanel.getCell(0, 0);   
  this._leftWidth = this._leftWidth + sz;
  $(left).width(this._leftWidth);
}